package com.talkology.pilot.teacher.controller;


import com.talkology.pilot.database.model.TeacherInfo;
import com.talkology.pilot.teacher.service.ITeacherInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老师信息管理控制器
 *
 * @author longJp
 * @Date 2018年12月19日
 */

@RestController
@RequestMapping(value = "/teacherInfo")
public class TeacherInfoController {
    @Autowired
    private ITeacherInfoService teacherInfoService;

    @RequestMapping(value = "/all", method= RequestMethod.GET)
    @ResponseBody
    public List<TeacherInfo> getTeacherByType(@RequestParam(value = "type", required = false) String type,
                                              @RequestParam(value = "pronounce", required = false) Byte pronounce) {
        if (type == null) {
            type = "IELTS";//设置一个默认值，防止出错
        }
        return teacherInfoService.getAllByFilter(type, pronounce);
    }

    @RequestMapping(value = "/add", method= RequestMethod.PUT)
    @ResponseBody
    public void addTeacherInfo(@RequestBody TeacherInfo teacherInfo) {
        teacherInfoService.add(teacherInfo);
    }

    @RequestMapping(value = "/update", method= RequestMethod.PUT)
    @ResponseBody
    public void updateTeacherInfo(@RequestBody TeacherInfo teacherInfo) {
        teacherInfoService.edit(teacherInfo);
    }

    @RequestMapping(value = "/delete", method= RequestMethod.DELETE)
    @ResponseBody
    public void deleteTeacherInfo(@RequestParam(value = "index", required = false) Long index) {
        teacherInfoService.delete(index);
    }
}
